export default {
    mounted() {
        this.$nextTick(() => {
            this.creatDOMOL()
            this.creatDOMLP()
        })
    },
    methods: {
        // creatDOMOL() {
        //     if (this.layerList2[1].children.DOMOL.show) {
        //         var imageryProvider = new Cesium.ArcGisMapServerImageryProvider({
        //             url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
        //             enablePickFeatures: false
        //         })
        //         this.imageLayerDOMOL = this.$viewer.imageryLayers.addImageryProvider(imageryProvider)
        //     }
        // },
        creatDOMOL() {
            if (this.layerList2[1].children.DOMOL.show) {
                var NaturalEarthII = new Cesium.TileMapServiceImageryProvider({
                    url: Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII')
                })
                this.imageLayerDOMLocal = this.$viewer.imageryLayers.addImageryProvider(NaturalEarthII)
                if (process.env.NODE_ENV === 'guangdong') {
                    this.addAcrGis()
                } else {
                    this.addAcrGis()
                }
            }
        },
        addAcrGis() {
            var imageryProvider = new Cesium.ArcGisMapServerImageryProvider({
                url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
                enablePickFeatures: false
            })
            this.imageLayerDOMOL = this.$viewer.imageryLayers.addImageryProvider(imageryProvider)
        },
        addTDT() {
            var tiandituTk = '6f2afe410bfcae554dee49b9127a6c84'
            var subdomains = ['0', '1', '2', '3', '4', '5', '6', '7']
            var imageryProvider = new Cesium.WebMapTileServiceImageryProvider({
                // 影像底图
                url: 'http://t{s}.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=' +
                    tiandituTk,
                subdomains: subdomains,
                layer: 'tdtBasicLayer',
                style: 'default',
                format: 'image/jpeg',
                tileMatrixSetID: 'GoogleMapsCompatible', // 使用谷歌的瓦片切片方式
                maximumLevel: 18,
                show: true
            })
            this.imageLayerDOMOL = this.$viewer.imageryLayers.addImageryProvider(imageryProvider)
        },
        addSuper() {
            var url = 'http://183.6.105.178:8190/iserver/services/map-ugcv5-DOM/rest/maps/DOM'
            this.$axios.get(url + '.json').then(res => {
                console.log(res.data)
                var scales84 = [3.38032714321E-9, 6.76065428641E-9, 1.352130857282E-8, 2.704261714564E-8, 5.408523429128E-8,
                    1.0817046858257E-7, 2.1634093716514E-7, 4.3268187433028E-7, 8.6536374866056E-7, 1.73072749732112E-6,
                    3.46145499464224E-6, 6.92290998928448E-6, 1.3845819978568952E-5, 2.7691639957137904E-5,
                    5.538327991427581E-5, 1.1076655982855162E-4, 2.2153311965710323E-4, 4.4306623931420646E-4,
                    8.861324786284129E-4, 0.0017722649572568258, 0.0035445299145136517, 0.007089059829027303
                ]

                var scalesweb = [1.69016357160E-9, 3.38032714321E-9, 6.76065428641E-9, 1.352130857282E-8, 2.704261714564E-8,
                    5.408523429128E-8, 1.0817046858257E-7, 2.1634093716514E-7, 4.3268187433028E-7, 8.6536374866056E-7,
                    1.73072749732112E-6, 3.46145499464224E-6, 6.92290998928448E-6, 1.3845819978568952E-5,
                    2.7691639957137904E-5, 5.538327991427581E-5, 1.1076655982855162E-4, 2.2153311965710323E-4,
                    4.4306623931420646E-4, 8.861324786284129E-4, 0.0017722649572568258, 0.0035445299145136517,
                    0.007089059829027303
                ]
                var name = res.data.name
                // var rectangle = Cesium.Rectangle.fromDegrees(result.bounds.left, result.bounds.bottom, result.bounds.right, result.bounds.top)
                var rectangle = Cesium.Rectangle.fromDegrees(-180, -90, 180, 90)
                var epsgcode = res.data.prjCoordSys.epsgCode
                console.log(epsgcode, 'epsgcode')
                var tilingScheme = ''
                var minlevel = 0
                var maxlevel = 17
                var originx = 0
                var originy = 0
                if (epsgcode === 4326) {
                    tilingScheme = new Cesium.GeographicTilingScheme({
                        numberOfLevelZeroTilesX: 2,
                        numberOfLevelZeroTilesY: 1
                    })
                    originx = -180
                    originy = 90
                }
                if (epsgcode === 3857) {
                    tilingScheme = new Cesium.WebMercatorTilingScheme()
                    originx = -20037508.34
                    originy = 20037508.34
                }

                var layerProvider = new Cesium.UrlTemplateImageryProvider({
                    url: url +
                        "/tileImage.png?transparent=true&cacheEnabled=true&width=256&height=256&x={x}&y={y}&scale={scale}&redirect=false&overlapDisplayed=false&origin={'x':" +
                        originx + ",'y':" + originy + '}',
                    rectangle: rectangle,
                    minimumLevel: minlevel || 0,
                    maximumLevel: maxlevel || 22,
                    tilingScheme: tilingScheme,
                    customTags: {
                        scale: function(imageryProvider, x, y, level) {
                            if (epsgcode === 4326) {
                                return scales84[level]
                            }
                            if (epsgcode === 3857) {
                                return scalesweb[level]
                            }
                        }
                    }
                })
                this.imageLayerDOMOL = this.$viewer.imageryLayers.addImageryProvider(layerProvider)
            })
        },
        clearDOMOL() {
            this.imageLayerDOMOL && this.$viewer.imageryLayers.remove(this.imageLayerDOMOL)
            this.imageLayerDOMLocal && this.$viewer.imageryLayers.remove(this.imageLayerDOMLocal)
        },
        creatDOMLP() {
            if (this.layerList2[1].children.DOMLP.show) {
                var imageryProvider = new Cesium.UrlTemplateImageryProvider({
                    url: '/mapData/guangdong/dom/{z}/{x}/{y}.png',
                    tilingScheme: new Cesium.GeographicTilingScheme(), // WebMercatorTilingScheme //GeographicTilingScheme
                    fileExtension: 'png',
                    minimumLevel: 0,
                    maximumLevel: 19
                })
                this.imageLayerDOMLP = this.$viewer.imageryLayers.addImageryProvider(imageryProvider)
            }
        },
        clearDOMLP() {
            this.imageLayerDOMLP && this.$viewer.imageryLayers.remove(this.imageLayerDOMLP)
        }

    }
}
